package com.hyperion.blog.controller;

import com.hyperion.blog.common.aop.LogAnnotation;
import com.hyperion.blog.service.TagsService;
import com.hyperion.blog.vo.ErrorCode;
import com.hyperion.blog.vo.result.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author Hyperion
 */
@RestController
@RequestMapping("/tags")
public class TagsController {

    @Resource
    private TagsService tagsService;

    TagsController(TagsService tagsService) {
        this.tagsService = tagsService;
    }

    @GetMapping
    public Result tags() {
        return Result.success(tagsService.findAll());
    }

    @GetMapping("/detail")
    public Result tagsDetail() {
        return Result.success(tagsService.findAllDetail());
    }

    @GetMapping("/detail/{id}")
    public Result tagDetail(@PathVariable("id") Long tagId) {
        Object allDetailById = tagsService.findAllDetailById(tagId);
        if (allDetailById == null) {
            return Result.fail(ErrorCode.PARAMS_ERROR);
        }
        return Result.success(allDetailById);
    }

    @GetMapping("/hot")
    @LogAnnotation(clazz = "TagsController", method = "hot")
    public Result hot() {
        int limit = 3;
        return Result.success(tagsService.hots(limit));
    }

}
